package com.lagou.edu;

public class NPSModel {
    String templete;
    String result = "";
    int id = 0;

    public NPSModel addConfig(String port, String type){
        String[] split = port.split("/");
        int length = split.length;
        if (length ==1) {
            String templet = "*#*{\"Id\":%s,\"Port\":%s\"ServerIp\":\"0.0.0.0\",\"Mode\":\"%s\",\"Status\":true,\"RunStatus\":true,\"Client\":{\"Cnf\":{\"U\":\"\",\"P\":\"\",\"Compress\":false,\"Crypt\":false},\"Id\":2,\"VerifyKey\":\"013whyee8zznnrlz\",\"Addr\":\"112.10.170.34\",\"Remark\":\"机械师笔记本\",\"Status\":true,\"IsConnect\":false,\"RateLimit\":0,\"Flow\":{\"ExportFlow\":42651149,\"InletFlow\":190921,\"FlowLimit\":0},\"Rate\":{\"NowRate\":0},\"NoStore\":false,\"NoDisplay\":false,\"MaxConn\":0,\"NowConn\":0,\"WebUserName\":\"\",\"WebPassword\":\"\",\"ConfigConnAllow\":false,\"MaxTunnelNum\":0,\"Version\":\"0.26.10\"},\"Ports\":\"\",\"Flow\":{\"ExportFlow\":7238628,\"InletFlow\":2116,\"FlowLimit\":0},\"Password\":\"\",\"Remark\":\"\",\"TargetAddr\":\"\",\"NoStore\":false,\"LocalPath\":\"\",\"StripPre\":\"\",\"Target\":{\"TargetStr\":\"%s\",\"TargetArr\":null,\"LocalProxy\":false},\"MultiAccount\":null,\"HealthCheckTimeout\":0,\"HealthMaxFail\":0,\"HealthCheckInterval\":0,\"HealthNextTime\":\"0001-01-01T00:00:00Z\",\"HealthMap\":null,\"HttpHealthUrl\":\"\",\"HealthRemoveArr\":null,\"HealthCheckType\":\"\",\"HealthCheckTarget\":\"\"}\n";
            result += String.format(templet, ++ id, port, type, port);
            return this;
        } else if (length ==2) {
            int start = Integer.valueOf(split[0]);
            int end = Integer.valueOf(split[1]);

            for (int i=start;i<=end;i++){
                String templet = "*#*{\"Id\":%s,\"Port\":%s\"ServerIp\":\"0.0.0.0\",\"Mode\":\"%s\",\"Status\":true,\"RunStatus\":true,\"Client\":{\"Cnf\":{\"U\":\"\",\"P\":\"\",\"Compress\":false,\"Crypt\":false},\"Id\":2,\"VerifyKey\":\"013whyee8zznnrlz\",\"Addr\":\"112.10.170.34\",\"Remark\":\"机械师笔记本\",\"Status\":true,\"IsConnect\":false,\"RateLimit\":0,\"Flow\":{\"ExportFlow\":42651149,\"InletFlow\":190921,\"FlowLimit\":0},\"Rate\":{\"NowRate\":0},\"NoStore\":false,\"NoDisplay\":false,\"MaxConn\":0,\"NowConn\":0,\"WebUserName\":\"\",\"WebPassword\":\"\",\"ConfigConnAllow\":false,\"MaxTunnelNum\":0,\"Version\":\"0.26.10\"},\"Ports\":\"\",\"Flow\":{\"ExportFlow\":7238628,\"InletFlow\":2116,\"FlowLimit\":0},\"Password\":\"\",\"Remark\":\"\",\"TargetAddr\":\"\",\"NoStore\":false,\"LocalPath\":\"\",\"StripPre\":\"\",\"Target\":{\"TargetStr\":\"%s\",\"TargetArr\":null,\"LocalProxy\":false},\"MultiAccount\":null,\"HealthCheckTimeout\":0,\"HealthMaxFail\":0,\"HealthCheckInterval\":0,\"HealthNextTime\":\"0001-01-01T00:00:00Z\",\"HealthMap\":null,\"HttpHealthUrl\":\"\",\"HealthRemoveArr\":null,\"HealthCheckType\":\"\",\"HealthCheckTarget\":\"\"}\n";
                result += String.format(templet, ++ id, i,type,i);
            }
            return this;
        } else {
            throw new RuntimeException("prot格式错误：" + port);
        }
    }

    public String getTemplete() {
        return templete;
    }

    public void setTemplete(String templete) {
        this.templete = templete;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
}
